package com.bzkj.web.controller.ncc;

import com.bzkj.basicinfo.domain.ncc.dto.NccBasicStoStockDto;
import com.bzkj.basicinfo.domain.ncc.NccBasicStoStock;
import com.bzkj.basicinfo.service.ncc.NccBasicStoStockService;
import com.bzkj.common.annotation.LogC;
import com.bzkj.common.core.controller.BaseController;
import com.bzkj.common.core.domain.AjaxResult;
import com.bzkj.common.core.domain.R;
import com.bzkj.common.core.page.TableDataInfo;
import com.bzkj.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Size;
import java.util.List;

@Api(tags = "仓库管理")
@RestController
@RequestMapping("/ncc/basic/StoStock")
public class NccBasicStoStockController extends BaseController {

    @Autowired
    private NccBasicStoStockService stoStockService;

    /**
     * NCC仓库信息定时任务
     */
    @GetMapping({"/nccBasicStoStockJob", "/nccBasicStoStockJob/{all}"})
    @PreAuthorize("@ss.hasPermi('ncc:StoStock:Job')")
    public void nccBasicStoStockJob(@PathVariable(required = false) String all) {
        stoStockService.updateNccBasicStoStockJob(all);
    }

    /**
     * 根据pkStoDoc修改仓库状态
     *
     * @Author wangzhichao
     * @Date 2024/12/05 17:06:14
     * @Param state 状态
     * @Param pkStoDoc 主键
     */
    @PreAuthorize("@ss.hasPermi('basic:nccBasic:stateEdit')")
    @PutMapping("/nccBasicStoStockEnableState")
    @ApiOperation(value = "修改状态接口", httpMethod = "PUT")
    @LogC(title = "ncc仓库信息", businessType = BusinessType.UPDATE,
            tableNames = "ncc_basic_sto_stock", pkFieldNames = "pk_sto_doc", content = "' 仓库ID：'+#pkStoDoc")
    public AjaxResult nccBasicStoStockEnableState(@RequestParam(value = "state", defaultValue = "1") @Size String state, @RequestParam("pkStoDoc") String pkStoDoc) {
        return stoStockService.nccBasicStoStockEnableState(state, pkStoDoc);
    }


    /**
     * 根据pK_STORDOC修改仓库信息
     *
     * @Author wangzhichao
     * @Date 2024/12/06 08:32:56
     * @Param entity
     */
    @PreAuthorize("@ss.hasPermi('basic:nccBasic:edit')")
    @PutMapping("/nccBasicStoStockUpdate")
    @ApiOperation(value = "修改接口", httpMethod = "PUT")
    @LogC(title = "ncc仓库信息", businessType = BusinessType.UPDATE,
            tableNames = "ncc_basic_sto_stock", pkFieldNames = "pk_sto_doc", content = "' 仓库名称：'+#entity.name")
    public AjaxResult nccBasicStoStockUpdate(@RequestBody NccBasicStoStock entity) {
        return stoStockService.nccBasicStoStockUpdate(entity);
    }

    /**
     * 根据条件分页查询仓库信息
     *
     * @Author wangzhichao
     * @Date 2024/12/06 08:57:38
     * @Param dto 查询条件
     * @Param page 分页条件
     */
    @PreAuthorize("@ss.hasPermi('basic:nccBasic:query')")
    @GetMapping("/findNccBasicStoStockData")
    @ApiOperation(value = "查询接口", httpMethod = "GET")
    public TableDataInfo findNccBasicStoStockData(NccBasicStoStockDto dto) {
        startPage();
        return getDataTable(stoStockService.findNccBasicStoStockData(dto));
    }

    /**
     * TODO 保存仓库信息
     *
     * @Author wangzhichao
     * @Date 2024/12/06 09:30:54
     * @Param entity
     */
    @PreAuthorize("@ss.hasPermi('basic:nccBasic:add')")
    @PostMapping("/nccBasicStoStockSave")
    @ApiOperation(value = "新增接口", httpMethod = "POST")
    @LogC(title = "ncc仓库信息", businessType = BusinessType.INSERT,
            tableNames = "ncc_basic_sto_stock", pkFieldNames = "id", content = "' 仓库名称：'+#entity.name")
    public AjaxResult nccBasicStoStockSave(@RequestBody NccBasicStoStock entity) {
        return stoStockService.nccBasicStoStockSave(entity);
    }

    /**
     * 查询所有ncc仓库信息
     *
     * @Author wangzhichao
     * @Date 2024/12/18 08:39:47
     */
    @GetMapping("findNccBasicStoStockAll")
    public R findNccBasicStoStockAll() {
        return stoStockService.findNccBasicStoStockAll();
    }

    /**
     * 模糊查询仓库名称信息
     *
     * @param name
     * @return
     */
    @PreAuthorize("@ss.hasPermi('basic:nccBasic:query')")
    @GetMapping("findNccBasicStoStockName")
    public List<String> findNccBasicStoStockName(String name) {
        return stoStockService.findNccBasicStoStockName(name);
    }

    /**
     * 仓库定时任务执行方法
     *
     * @return
     */
    @GetMapping("jobMethod")
    public R jobMethod() {
        return stoStockService.jobMethodExecute(false);
    }

}
